/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.SQLException;
import pojo.QuyDinh;

/**
 *
 * @author Thanh Minh
 */
public class QuyDinhDAO {

    public static int themQuyDinh(QuyDinh QD) {
        int n = -1;
        try {
            MysqldataAccesshelper helper = new MysqldataAccesshelper();
            helper.open();
            String sql = String.format("INSERT INTO quydinh (MaQuyDinh,TenQuyDinh,GiaTri) VALUES (%d,'%s',%d)", QD.getMaQuyDinh(), QD.getTenQuyDinh(), QD.getGiaTri());
            n = helper.executeUpdate(sql);
            helper.close();
        } catch (SQLException ex) {
            System.out.println("Them that bai" + ex);
        }

        return n;
    }
    public static int suaQuyDinh(int maQD,String tenQD , int GiaTri) {
        int n = -1;
        try {
            MysqldataAccesshelper helper = new MysqldataAccesshelper();
            helper.open();
            String sql = String.format("UPDATE  quydinh SET TenQuyDinh='%s' ,GiaTri=%d where MaQuyDinh=%d ",tenQD,GiaTri,maQD);
            n = helper.executeUpdate(sql);
            helper.close();
        } catch (SQLException ex) {
            System.out.println("Cap nhat that bai" + ex);
        }

        return n;
    }
    public static int xoaQuyDinh(int maQD) {
        int n = -1;
        try {
            MysqldataAccesshelper helper = new MysqldataAccesshelper();
            helper.open();
            String sql = String.format("DELETE FROM quydinh WHERE MaQuyDinh=%d ",maQD);
            n = helper.executeUpdate(sql);
            helper.close();
        } catch (SQLException ex) {
            System.out.println("Xoa that bai" + ex);
        }

        return n;
    }
}
